package com.ichengzi.audit.human.repository.es.service.impl;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.transport.endpoints.BooleanResponse;
import com.ichengzi.audit.human.repository.es.service.ElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author lihn
 */
@Service
public class ElasticSearchServiceImpl implements ElasticSearchService {
    @Autowired
    private ElasticsearchClient client;

    @Override
    public boolean createIndex(String indexName) {
        try {
            client.indices().create(c -> c.index(indexName));
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean existsIndex(String indexName) {
        try {
            BooleanResponse booleanResponse = client.indices().exists(e -> e.index(indexName));
            return booleanResponse.value();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @Override
    public void deleteIndex(String indexName) {
        try {
            client.indices().delete(d -> d.index(indexName));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void addDocument(String index, Object doc) {

    }

    @Override
    public void updateDocument(String index, String id, Object doc) {

    }

    @Override
    public void getDocumentById(String index, String id) {

    }

    @Override
    public void bulkInsert(String index, List<Object> docs) {

    }
}
